package fightplan.views.tables;

import java.awt.Component;
import java.awt.Window;
import java.util.EventObject;

import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.event.CellEditorListener;
import javax.swing.table.TableCellEditor;

public class InfoCellEditor implements TableCellEditor {

	public TableCellEditor delegate;
	public JTable table;

	public InfoCellEditor(TableCellEditor delegate) {
		this.delegate = delegate;
	}

	public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
		this.table = table;
		return delegate.getTableCellEditorComponent(table, value, isSelected, row, column);
	}

	public boolean stopCellEditing() {
		try {
			return delegate.stopCellEditing();
		} catch (Exception x) {
			Window window = SwingUtilities.getWindowAncestor(table);
			JOptionPane.showMessageDialog(window, x.getCause().getMessage(), "Ungültige Eingabe",
					JOptionPane.WARNING_MESSAGE);
			return false;
		}
	}

	// delegation

	public void addCellEditorListener(CellEditorListener l) {
		delegate.addCellEditorListener(l);
	}

	public void cancelCellEditing() {
		delegate.cancelCellEditing();
	}

	public Object getCellEditorValue() {
		return delegate.getCellEditorValue();
	}

	public boolean isCellEditable(EventObject anEvent) {
		return delegate.isCellEditable(anEvent);
	}

	public void removeCellEditorListener(CellEditorListener l) {
		delegate.removeCellEditorListener(l);
	}

	public boolean shouldSelectCell(EventObject anEvent) {
		return delegate.shouldSelectCell(anEvent);
	}

}
